﻿using DataServer.Entities;
using IsPay.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IsPay.View
{
    public partial class ModifyAccuntPWD : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UserProfile loginuser;
            if (Session["USERID"] == null || Session["USERID"].ToString().Length <= 0 || Session["LOGINUSER"] == null)
            {
                Response.Write("<script>top.location='../Default.aspx'</script>");
            }
            if(Request.Params["txtpwdold"]!=null&& Request.Params["txtpwdnew1"] != null&& Request.Params["txtpwdnew2"] != null)
            {
                String strpwdold = Request.Params["txtpwdold"].ToString();
                String strpwdnew1 = Request.Params["txtpwdnew1"].ToString();
                String strpwdnew2 = Request.Params["txtpwdnew2"].ToString();
                if(!strpwdnew1.Equals(strpwdnew2)|| strpwdnew1.Length <= 0)
                {
                    lblmsg.Text = "两次输入的密码不一致";
                    return;
                }
                loginuser=(UserProfile)Session["LOGINUSER"];
                if (loginuser.AccuntId == null || loginuser.AccuntId.Length <= 0)
                {
                    lblmsg.Text = "当前登录用户未绑定账户，请先绑定账户";
                    return;
                }
                String acctid = loginuser.AccuntId;
                String oldpwdmd5 = CodeMange.getMD5StringCode(strpwdold);
                AccuntSer actser = new AccuntSer();
                Accunt ac = actser.GetAccuntByIDPWD(acctid, oldpwdmd5);
                if(ac==null|| ac.AccuntId==null||ac.AccuntId.Length <= 0)
                {
                    lblmsg.Text = "输入的旧密码错误";
                    return;
                }else
                {
                    ac.AccuntPayPWD = CodeMange.getMD5StringCode(strpwdnew1);
                    ac.LastModifyer = Session["USERID"].ToString();
                    ac.LastModifyTime= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    List<Accunt> lsac = new List<Accunt>();
                    lsac.Add(ac);
                    String strresoult = actser.ModifyAccunt(lsac, Session["USERID"].ToString());
                    if (strresoult.Equals("OK"))
                    {
                        lblmsg.Text = "更新成功";
                    }
                    else
                    {
                        lblmsg.Text = strresoult;
                    }
                

                }

            }
        }
    }
}